const webpack = require('webpack')
const path = require('path')
const proxyConfig = require('./config/proxyConfig.js')
const urlConfig = require('./config/config.json')

console.log(process.env.NODE_ENV)
function resolve(dir) {
  return path.join(__dirname, dir)
}

module.exports = {
  publicPath: './',
  productionSourceMap: false,
  lintOnSave: false,
  configureWebpack: config => {
    // 本地联调打开，不然没有debugger断点、JS文件也会压缩成乱码
    config.devtool = 'source-map'
    if (process.env.NODE_ENV == 'production') {
      config.plugins.forEach(val => {
        if (val.__pluginName === 'html') {
          val.options.configUrl = './config.js?v=' + Date.now()
        }
      })
    }

    config.plugins.push(
      new webpack.DefinePlugin({
        APP: {
          CONFIG: JSON.stringify(urlConfig[process.env.NODE_ENV])
        }
      })
    )

    return {
      resolve: {
        alias: {
          '@api': resolve('./src/api'),
          '@dist': resolve('./dist'),
          '@root': resolve('./'),
          'langCustom': resolve('./src/lang')
        }
      }
    }
  },
  devServer: {
    host: 'sassp-web.cras-uat.crc.com.cn',
    port: 7003,
    open: true,
    historyApiFallback: true,
    noInfo: true,
    disableHostCheck: true,
    proxy: proxyConfig,
    inline: true
  }
}
